class computerPlayer {
  constructor(id) {
    this.id = id;
  }
  //   开始移动
  startMove() {
    setInterval(computerMove, 1000); // 每隔1000毫秒（1秒）执行myFunction
  }
  updateFirePoint() {
    for (let i = 0; i < computer_players_tank.length; i++) {
      const element = computer_players_tank[i];
      const x_point = player_tank.tank_pointer[0];
      const y_point = player_tank.tank_pointer[1];
      send(
        JSON.stringify({
          type: "gun",
          id: element.id,
          x: x_point,
          y: y_point,
        })
      );
      // element.updateTankGunRotate([x_point, y_point])
    }
  }
}

// 电脑坦克移动
function computerMove() {
  for (let i = 0; i < computer_players_tank.length; i++) {
    const element = computer_players_tank[i];
    let random_number = random(1, 4); // 输出一个1到4之间的随机整数
    if (random_number == 1) {
      element.orientation.top = true;
    } else if (random_number == 2) {
      element.orientation.left = true;
    } else if (random_number == 3) {
      element.orientation.bottom = true;
    } else {
      element.orientation.right = true;
    }
    let random_time = random(1, 10000);
    // 在1000毫秒（1秒）后取消定时器
    setTimeout(function () {
      if (element.orientation.top == true) {
        element.orientation.top = false;
      } else if (element.orientation.left == true) {
        element.orientation.left = false;
      } else if (element.orientation.bottom == true) {
        element.orientation.bottom = false;
      } else {
        element.orientation.right = false;
      }
      all_bullet.push(element.fire());
    }, random_time);
  }
}

// 随机数
function random(min, max) {
  return Math.floor(Math.random() * (max - min + 1) + min);
}
